package com.xxxy.dongyexuan.action;

import com.xxxy.dongyexuan.mapper.IEmpMapper;
import com.xxxy.dongyexuan.mapper.ILevelMapper;
import com.xxxy.dongyexuan.po.Emp;
import com.xxxy.dongyexuan.po.Level;
import com.xxxy.dongyexuan.po.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class EmpAction {

    @Autowired
    private IEmpMapper mapper;

    //分页查询
    @GetMapping("/emp/{pagenow}/{pagesize}")
    public PageBean findByPage(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getEmpCount();//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPage(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    //分页查询
    @GetMapping("/empfirstmeirong/{pagenow}/{pagesize}")
    public PageBean findByPagefirstmeirong(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getcount(1, 1);//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPagefirstmeirong(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    //分页查询
    @GetMapping("/empsecondmeirong/{pagenow}/{pagesize}")
    public PageBean findByPagesecondmeirong(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getcount(1, 2);//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPagesecondmeirong(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    //分页查询
    @GetMapping("/empthirdmeirong/{pagenow}/{pagesize}")
    public PageBean findByPagethirdmeirong(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getcount(1, 3);//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPagethirdmeirong(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    //分页查询
    @GetMapping("/empfirstmeifa/{pagenow}/{pagesize}")
    public PageBean findByPagefirstmeifa(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getcount(2, 1);//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPagefirstmeifa(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    //分页查询
    @GetMapping("/empseconodmeifa/{pagenow}/{pagesize}")
    public PageBean findByPagesecondmeifa(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getcount(2, 2);//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPagesecondmeifa(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    //分页查询
    @GetMapping("/empthirdmeifa/{pagenow}/{pagesize}")
    public PageBean findByPagethirdmeifa(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        int from = (pagenow - 1) * pagesize;//开始条数
        int total = this.mapper.getcount(2, 3);//总条数
        int pages = (total - 1) / pagesize + 1;//计算总页数
        List data = this.mapper.findByPagethirdmeifa(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }


    //查询所有
    @GetMapping("/emp")
    public List<Emp> findAll() {
        List<Emp> list = this.mapper.findAll();
        return list;
    }

    // 查询排名前5的美容美发师
    @GetMapping("/topFiveEmp")
    public List<Emp> topFiveEmp() {

        return this.mapper.topFiveEmp();
    }

    // 查询促销的美容美发师
    @GetMapping("/promotionEmp")
    public List<Emp> promotionEmp() {

        return this.mapper.promotionEmp();
    }

    //查询所有
    @GetMapping("/empfirstmeirong")
    public List<Emp> findfirstmeirong() {
        List<Emp> list = this.mapper.findfirstmeirong();
        return list;
    }

    //根据员工号查询
    @GetMapping("/emp/{eid}")
    public Emp findById(@PathVariable("eid") int eid) {
        Emp emp = this.mapper.findById(eid);
        return emp;
    }

    //增加
    @PostMapping("/emp")
    public int save(Emp emp) {
        int result = this.mapper.save(emp);
        return result;
    }

    //修改
    @PutMapping("/emp")
    public int update(Emp emp) {
        int result = this.mapper.merge(emp);
        return result;
    }

    //删除
    @DeleteMapping("/emp/{eid}")
    public int delete(@PathVariable("eid") int eid) {
        int result = this.mapper.delete(eid);
        return result;
    }
}